home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2016 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  80 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: question on pass-by-reference
  5. Date: Thu, 18 Jan 96 13:13:31 GMT
  6. Organization: none
  7. Message-ID: <821970811snz@genesis.demon.co.uk>
  8. References: <4dha4j$4qg@shrike.depaul.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4dha4j$4qg@shrike.depaul.edu>
  15.            kmurakam@shrike.depaul.edu "Kazuki Murakami" writes:
  16.  
  17. >I have a question on pass-by-reference.
  18.  
  19. You mean passing pointers. C doesn't support any form of pass by reference.
  20.  
  21. >Here is a problem, I want to set array of unsigned short number to be all 0
  22. > using a function.
  23. >here is what set looks like:
  24. >        typedef unsigned short USHORT;
  25. >        typedef  USHORT SET[32];
  26.  
  27. Because of the way C handles arrays typedefing them can lead to a great
  28. deal of confusion - it is generally best to avoid doing this.
  29.  
  30. >here is the setInit, which will initialize set to be 0,
  31. >        void setInit (SET *s)
  32. >        {
  33. >            int i;
  34. >
  35. >            for (i=0; i<32; i++)
  36. >            {
  37. >                *s[i] = 0;
  38.  
  39. This needs to be:
  40.  
  41.                 (*s)[i] = 0;
  42. >            }
  43. >        }
  44. >
  45. >here is the calling function.
  46. >        setInit(&set1);  setInit(&set2);
  47. >
  48. >I think there is somthing wrong in "setInit" function but I cannot seem to
  49. > figure out what that is.
  50.  
  51. Your code was trying walk through an array of sets whereas you wanted to
  52. walk through the elements of a single set.
  53.  
  54. >If somebody can figure out what that is or some other way of initializing "SET
  55.  
  56. #include <string.h>
  57.  
  58. void setInit (SET *s)
  59. {
  60.     memset(s, 0, sizeof(SET));
  61. }
  62.  
  63. or
  64.  
  65. void setInit (SET s)
  66. {
  67.     memset(s, 0, sizeof(SET));
  68. }
  69.  
  70. which would be called with, say:
  71.  
  72.     setInit(set1);  setInit(set2);
  73.  
  74.  
  75. -- 
  76. -----------------------------------------
  77. Lawrence Kirby | fred@genesis.demon.co.uk
  78. Wilts, England | 70734.126@compuserve.com
  79. -----------------------------------------
  80.